﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Restaurant.DTO;
using Restaurant.BUS;

namespace Restaurant
{
    public partial class frmDSDatCho : Form
    {
        private DatchoService dcService = new DatchoService();
        public bool fix = false;
        public bool unrepeat = false;
        public bool phantom = false;
        int soluong = 0;

        public frmDSDatCho()
        {
            InitializeComponent();
        }

        private void LoadDSDatCho(DataTable dbtab)
        {
            lbSoluong.Text = soluong.ToString();
            lv_DatCho.Items.Clear();
            if (dbtab.Rows.Count > 0)
            {
                for (int i = 0; i < dbtab.Rows.Count; i++)
                {
                    DataRow dbrow = dbtab.Rows[i];
                    ListViewItem liv = new ListViewItem();
                    liv.Text= dbrow["MaDatCho"].ToString();
                    liv.SubItems.Add(dbrow["TenKH"].ToString());
                    liv.SubItems.Add(dbrow["NgayDat"].ToString());
                    liv.SubItems.Add(dbrow["TenBan"].ToString());
                    liv.SubItems.Add(dbrow["SDT"].ToString());
                    lv_DatCho.Items.Add(liv);

                }
            }
            else
            {
                return;
            }
        }

        private void frmDSDatCho_Load(object sender, EventArgs e)
        {
            DataTable dbtab = new DataTable();
            if (!fix && !unrepeat && !phantom)
                dbtab = dcService.LoadDatCho();
            if (!fix && phantom)
                dbtab = dcService.LoadDatChoPhantomError(ref soluong);
            if(fix && phantom)
                dbtab = dcService.LoadDatChoPhantom(ref soluong);
            if (!fix && unrepeat)
                dbtab = dcService.LoadDatChoUnrepeatError(ref soluong);
            if (fix && unrepeat)
                dbtab = dcService.LoadDatChoUnrepeat(ref soluong);
            LoadDSDatCho(dbtab);
        }
    }
}
